/**
 * File Name: 
 * Description: 
 * Create Time: 2010-10-20
 * @Author: yue.chen  ( yue.chen2@hisoft.com )
 */
package com.hisoft.entity;

import java.util.ArrayList;
import java.util.List;

public class MailEntity {
	//发件人和地址
	private String from;
	//发件人
	private String fromPersonal;
	//发件地址
	private String fromAddress;
	//发件主题
	private String subject;
	//邮件内容
	private String content;
	//邮件文本内容
	private String contentText;
	//发送时间
	private String SentDate;
	//发送地址
	private String mailTo;
	//是否已读
	private boolean hasRead;

	public String getMailTo() {
		return mailTo;
	}

	public void setMailTo(String mailTo) {
		this.mailTo = mailTo;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public boolean isHasRead() {
		return hasRead;
	}

	public void setHasRead(boolean hasRead) {
		this.hasRead = hasRead;
	}

	public String getSentDate() {
		return SentDate;
	}

	public void setSentDate(String sentDate) {
		SentDate = sentDate;
	}

	public String getFromPersonal() {
		return fromPersonal;
	}

	public void setFromPersonal(String fromPersonal) {
		this.fromPersonal = fromPersonal;
	}

	public String getFromAddress() {
		return fromAddress;
	}

	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setContentText(String content) {
		this.contentText = content;
	}

	public String getContentText() {
		if (contentText == null || contentText.isEmpty()) {
			List<String> tempList = new ArrayList<String>();
			String contentText = this.getContent();
			int endPlace = 0;
			int startPlace = 0;
			while (true) {
				startPlace = this.getContent().indexOf("<", endPlace);
				endPlace = this.getContent().indexOf(">", endPlace) + 1;
				if (startPlace == -1 || endPlace == -1)
					break;
				tempList.add(new String(this.getContent().substring(startPlace, endPlace)));
			}
			for (String i : tempList) {
				contentText = contentText.replace(i, "");
			}
			contentText = contentText.replaceAll("\r\n", "\n");
			contentText = contentText.replaceAll("\r \n", "\n");
			return contentText;
		}
		return contentText;
	}

	public String getFirstLinksContent() {
		String URL = null;
		int temp;
		URL = this.content.substring(temp = content.toLowerCase().indexOf("<a href=") + 9, content.toLowerCase().indexOf("\">", temp));
		if (URL.contains("http"))
			return URL;
		else
			return "";
	}

	public String getRedContent() {
		String redString = null;
		String tempFlag = "<font color=\"red\">";
		int temp = content.toLowerCase().indexOf(tempFlag) + tempFlag.length();
		if (temp == 17)
			return "";
		else
			redString = this.content.substring(temp, content.toLowerCase().indexOf("</font>", temp));
		return redString;
	}

}
